﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using System.Text.RegularExpressions;

namespace Domain
{
    public abstract class Operador : DomainObject
    {
        public long UserName { get; set; }

        [StringLengthValidator(5, 20, MessageTemplate = "Debe especificar una contraseña entre 5 y 20 caracteres.")]
        public string Password { get; set; }

        public string EMail { get; set; }

        public Operador() { }

        public Operador(long _UserName, string _Password, string _Email)
        {
            this.UserName = _UserName;
            this.Password = _Password;
            this.EMail = _Email;
        }

        [SelfValidation]
        public void Check_Mail(ValidationResults results)
        {
            if (EMail.Length < 7 || EMail.Length > 50)
            {
                results.AddResult(new ValidationResult("La cantidad de caracteres del mail debe ser entre 7 y 50", this, "", "", null));
                return;
            }

            string patron = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
            Regex re = new Regex(patron);

            if (!re.IsMatch(EMail))
            {
                results.AddResult(new ValidationResult("El Email especificado no es válido", this, "", "", null));
                return;
            }           
            
        }

    }
}
